Skip to content

vk: cache sampler_for's samplers until a sampler registration changes - #901

Merged
NotRexed merged 1 commit into
NotRexed:mainfrom
MMajor87:sampler-cache
Nov 9, 2026
Merged

NotRexed merged 1 commit into
NotRexed:mainfrom
MMajor87:sampler-cache

Conversation

@MMajor87

@MMajor87 MMajor87 commented Nov 9, 2026

Copy link
Copy Markdown

What

sampler_for (vk_draw.cpp) runs for every texture slot of every descriptor build. Each call took reg_mu in sampler_of, copied the sampler registration, hashed it word by word and looked the hash up in a thread map: ~48,000 times a frame at ~3,000 draws.

It now keeps a thread table indexed by [compare][id] (ids are 12 bits), stamped with a new sampler registration generation (vk_bank.cpp). register_sampler_copy bumps that generation only when the registration's contents change, so rewrites of the same sampler don't empty the cache. The generation is read before the lookup, so a registration that lands during a miss makes the next call miss again. Samplers are never destroyed (as the existing per-thread map already assumes), so a cached VkSampler stays valid.

RX_VK_SAMPLER_CACHE=0 turns it off. 24 lines in two files; no shader stamp change (neither file is translator input).

Tested

Context and the full profile: #384.

🤖 Generated with Claude Code

…hanges

Each texture of each draw found its sampler through reg_mu, a copy of the
registration, a hash of it and a map lookup: ~48,000 times a frame at ~3,000
draws. sampler_for now keeps a thread table by id and compare, good while no
sampler registration's contents changed (a new generation in vk_bank.cpp,
bumped only when register_sampler_copy writes different contents).
RX_VK_SAMPLER_CACHE=0: off, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants